<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>学生作业</title>

	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
	<link rel="stylesheet" href="css/student_homework_detalis.css">
	<link rel="stylesheet" href="../css/main.css">
	<style>
		h3 {
			font-size: 25px;
			margin: 0 0;
			letter-spacing: 5px;
		}

		.content {
			margin-top: 20px;
			border: 1px solid #eceaff;
			background: #eceaff;
			border-radius: 5px;
		}
	</style>
</head>

<body style="background: #eceaff;">
	<div id="container">
		<div class="contain" id="vue-root">
			<div class="header">
				<div class="header_title">作业详情</div>
				<a onclick="history.back()">
					<img src="../image/return.png" alt="" class="return">
				</a>
			</div>
			<div style="height: 40px;"></div>
			<div class="content">
				<div class="homework_content">
					<h3 class="homework_info" v-text="homework.courseName+'作业'"></h3>
					<div class="homework_info" v-text="homework.publishTime"></div>
					<div class="homework_info" v-text="homework.classesName"></div>
					<div class="homework_info" v-text="homework.studentName"></div>
					<textarea id="text1" class="info" disabled="disabled" :value="homework.answer"></textarea>
				</div>
				<div class="img_box">
					<img v-for="pic in homework.pics" :src="getImg(pic)" style="margin-top: 2%;" class="homework_img" />
				</div>

				<textarea id="text2" class="text_left" placeholder="请老师批改" style="height:100px"
					:disabled="homework.status==2" v-model="homework.reply"></textarea>

				<button class="homework_detalis_button" v-if="homework.status==1" @click="submit">提交</button>

				<div v-if="homework.status==2" style="text-align: center; color:limegreen">已批改</div>

			</div>

		</div>

	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>

	<script src="/js/common.js"></script>

	<script>

		var teacher = getTeacher();

		var app = new Vue({
			el: '#vue-root',
			data: {
				homework: {
					status: 1,
					pics: []
				}
			},
			created: function () {
				this.getData();
			},
			methods: {
				getData: function () {
					var id = params().id;

					if (!id) {
						alert('参数错误');
						throw '找不到id';
					};

					axios.get('/t/homework/student/' + id).then(function (res) {
						var data = res.data;
						data.pics = data.pics ? data.pics.split('|') : [];
						this.homework = data;
					}.bind(this));
				},
				submit: function () {
					if (!confirm('确认提交？')) return;
					axios.post('/t/homework/reply', {
						id: this.homework.id,
						reply: this.homework.reply
					}).then(function (res) {
						this.getData();
					}.bind(this));
				},
				getImg: function (pic) {
					return '/static/' + teacher.schoolId + '/homework/' + pic;
				}
			}
		});


	</script>


</body>

</html>